package org.wlw.aspet;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Aspect
public class AopAdvice {
    @Pointcut("execution(* org.wlw.service.impl.*.add*(..))||execution(* org.wlw.service.impl.*.update*(..))||execution(* org.wlw.service.impl.*.delete*(..))")
    public void pc1() {

    }

    @Pointcut("execution(* org.wlw.service.impl.*.*(..))")
    public void pc2() {
    }

    @Before("pc1()")
    public void auth() {
        System.out.println("权限控制!");
    }

    @After("pc2()")
    public void log() {
        System.out.println("日志控制!");
    }

    @Around("pc2()")
    public Object statusTime(ProceedingJoinPoint proceedingJoinPoint) {
        try {
            long startTimes = new Date().getTime();
            Object rel = proceedingJoinPoint.proceed();
            long endTimes = System.currentTimeMillis();
            System.out.println(endTimes - startTimes);
            return rel;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return null;
    }
}
